package calcsdk.nw;

import calcsdk.Calcsdk;

public class FindDist {

    public static float[] find(float mas[][], int source, Calcsdk core) {
        int n = mas.length;
        float dist[] = new float[n];
        for (int i = 0; i < n; i++) {
            dist[i] = Float.POSITIVE_INFINITY;
        }
        dist[source] = 0;
        int mode[] = new int[n];//0 - processing, 1 - fixed
        //mode[source]=1;

        //boolean done=false;
        while (true) {
            int min = -1;
            float minDist = Float.POSITIVE_INFINITY;
            for (int i = 0; i < n; i++) {
                if (mode[i] == 0 && dist[i] < minDist) {
                    minDist = dist[i];
                    min = i;
                }
            }
            if (min == -1) {
                break;
            }

            for (int i = 0; i < n; i++) {
                if (mas[min][i] != mas[min][i]) {
                    continue;
                }
                float tDist = dist[min] + mas[min][i];
                if (dist[i] > tDist) {
                    dist[i] = tDist;
                }
            }
            mode[min] = 1;
            if (core.DEBUG) Util.arrayPrint(dist);
        }

        return dist;
    }
}
